package com.atguigu.stgy.admin.service.impl;

import com.atguigu.stgy.admin.service.ApartmentFacilityService;
import com.atguigu.stgy.model.dto.ApartmentDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.stgy.admin.mapper.ApartmentFacilityMapper;
import com.atguigu.stgy.model.entity.ApartmentFacility;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ApartmentFacilityServiceImpl extends ServiceImpl<ApartmentFacilityMapper, ApartmentFacility> implements ApartmentFacilityService {

    public void bathSaveFacility(ApartmentDTO apartmentDTO, Long apartmentInfoId) {

        if (CollectionUtils.isEmpty(apartmentDTO.getFacilityInfoIds())){
            return ;
        }
        List<ApartmentFacility> apartmentFacilities = apartmentDTO.getFacilityInfoIds().stream().map(facilityInfoId -> {


            ApartmentFacility apartmentFacility = new ApartmentFacility();
            apartmentFacility.setApartmentId(apartmentInfoId);
            apartmentFacility.setFacilityId(facilityInfoId);
            return apartmentFacility;

        }).collect(Collectors.toList());
        this.saveBatch(apartmentFacilities);
    }

}
